#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Author : Tinfeng

import requests
import json
from utils.FileRead import ReadYaml


class get_token:
    reader = ReadYaml()
    username = reader.get_value('login','username')
    password = reader.get_value('login','password')
    p = reader.get_value('login','face_url')

    def login_token(self):
        postdata = {"UserName": self.username, "PassWd": self.password, "pattern": None}
        headers = {'content-type': 'application/json'}
        r = requests.post(self.p, data=json.dumps(postdata),
                          headers=headers)
        token_str = r.text
        token_dict = json.loads(token_str)
        if token_dict['stats'] == 'YES':
            return token_dict["access_token"]
        else:
            return False

if __name__ == '__main__':
    c = get_token()
    print(c.login_token())